package terra.model.object.item;

import terra.definitions.item.ItemDef;
import terra.managers.DefManager;
import terra.model.Inventory;
import terra.model.object.GObject;
import terra.model.object.GameObject;
import terra.model.object.interfaces.Usable;
import terra.model.object.knownlist.NullKnownList;
import terra.model.object.knownlist.ObjectKnownList;
import terra.network.packet.Packet;

public class Item extends GameObject implements Usable {

	private static final long serialVersionUID = -3237628446031873628L;
	private int id = -1;
	private int count = 1;
	public String itemType;
	public Inventory owner;
	private int ownerObjectId;

	public Item(int objectId, ItemDef def, Inventory inv) {
		super(objectId);
		owner = inv;
		setCount(1);
		id = def.id;
		setName(def.name);
		setImage(def.image);
		itemType = def.itemType;
	}

	public ItemDef getDef() {
		return DefManager.allItems.get(id);
	}

	public void update(int delta) {

	}

	public void use() {
		System.out.println("use!" + this);
	}

	@Override
	public void objectChanged(GObject object) {

	}

	public int getOwnerObjectId() {
		return ownerObjectId;
	}

	public void setOwnerObjectId(int ownerObjectId) {
		this.ownerObjectId = ownerObjectId;
	}

	public int getCount() {
		return getDef().isStackable ? count : 1;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public void addCount(int value) {
		count += value;
	}

	@Override
	public Packet getInfo() {
		return null;
	}

	@Override
	public ObjectKnownList getKnownList() {
		if (knownList == null)
			return knownList = new NullKnownList(this);
		return knownList;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

}
